package jmine.tec.subscription.impl;

import jmine.tec.subscription.Publication;
import jmine.tec.subscription.PublicationListener;
import jmine.tec.subscription.Publisher;
import jmine.tec.subscription.SubscriptionSettings;

/**
 * Extende {@link PublicationListener} para renovar o timeout de um {@link SubscriptionSetImpl}
 * 
 * @author takeshi
 * @param <P> o tipo da publication
 */
final class RenewingPublicationListener<P extends Publication> implements PublicationListener<P> {
    private final SubscriptionSetImpl queueSubscriptionSet;

    private final PublicationListener<P> publicationListener;

    /**
     * C'tor
     * 
     * @param queueSubscriptionSet o {@link SubscriptionSetImpl} a ser renovado
     * @param publicationListener o {@link PublicationListener} a ser chamado
     */
    RenewingPublicationListener(SubscriptionSetImpl queueSubscriptionSet, PublicationListener<P> publicationListener) {
        this.queueSubscriptionSet = queueSubscriptionSet;
        this.publicationListener = publicationListener;
    }

    /**
     * {@inheritDoc}
     */
    public boolean isAssynchronous() {
        return publicationListener.isAssynchronous();
    }

    /**
     * {@inheritDoc}
     */
    public boolean isTransactionRequired() {
        return publicationListener.isTransactionRequired();
    }

    /**
     * {@inheritDoc}
     */
    public void onPublication(Publisher<P> publisher, SubscriptionSettings settings, P publication) {
        queueSubscriptionSet.renewTimeout();
        publicationListener.onPublication(publisher, settings, publication);
    }
}